<?php
$this->headTitle('Sửa thiết bị IT','append');
?>
<!-- Start Forms -->
<div class="grid grid_7">
    <div class="box-header">Cập nhật thiết bị</div>
    <div class="box">
        <?php
            if(isset($this->errorDate)){
                echo '<div class="notification error"><span class="strong">'.$this->errorDate.'</span></div>';
            }
            if($this->message !=''){
            	echo '<div class="notification error"><span class="strong">'.$this->message.'</span></div>';
            }
            echo $this->form;
            $owner = '<select name="owner_new[]">';
            if($this->owner_list){
                foreach($this->owner_list as $row){
                    $owner .= '<option value="'.$row['name'].'">'.$row['name'].'</option>';
                }
            } 
            $owner .= '</select>';
        ?>
		<script language="javascript">
        
			$("form > dl.zend_form > dd#iplan2-element").append('</br><input type="button" id="insertItem" name="insertItem" value ="Thêm thành phần thiết bị (Nếu có)" />');

			$('#insertItem').click(function(){
				$("form > dl.zend_form > dd#iplan2-element").append('<div class="fwrap"><div class = "mTit">Thông tin thành phần thiết bị</div><div class="content">'
															+'<div class = "row-1"><label class="first-row-label">Tên</label> <input type="text" name="item_new[]" size="20" />'
															+'</div><div class = "row-2"><div class="row-first"><label class="first-row-label">Giá Mua</label>  <input type="text" name="priceItem_new[]" size="20" /><div class="rcost"></div></div>'
															+'<div class="row-second"><label>Ngày mua</label> <input readOnly ="true" type="text" name="startDate_new[]" placeholder="mm/dd/yyyy" size="20" class="startDate" /></div>'
															+'<div class="clr"></div></div><div class = "row-5"><div class="row-first"><label class="first-row-label">Tài Sản</label><?php echo $owner;?></div>'
															+'<div class="clr"></div></div><div class = "row-4"><label class="first-row-label">Lịch sử</label> <textarea name="history_new[]" rows="3" cols ="50"></textarea></br>'															
															+'<label class="first-row-label">Thông Tin</label> <textarea name="info_new[]" rows="3" cols ="50"></textarea></br>'
															+'</div><input class="del" type="button" onclick="del(this);" value ="Xóa" /></div></div>');
				
                $(function () {
		            $(".startDate").datepicker({ changeMonth : true, changeYear: true, yearRange: '1950:3000' });
					$('input[name^="priceItem"]').keydown(function(event) {
                    	if( !(event.keyCode == 8                                // backspace
                            || event.keyCode == 9                               // tab
                            || event.keyCode == 46                              // delete
                            || (event.keyCode >= 35 && event.keyCode <= 40)     // arrow keys/home/end
                            || (event.keyCode >= 48 && event.keyCode <= 57)     // numbers on keyboard
                            || (event.keyCode >= 96 && event.keyCode <= 105))   // number on keypad
                            ) {
                                event.preventDefault();     // Prevent character input
                        }
                    });
                    $('input[name^="priceItem"]').keyup(function(){
                        $(this).val(partMonney($(this).val().replace(".", "")));
                        value = $(this).val().replace(".", "");
                        value = value.replace(".", "");
                        value = value.replace(".", "");
                        value = value.replace(".", "");
                        value = value.replace(".", "");
                        value = value.replace(".", "");
                        value = value.replace(".", "");
                        value = value.replace(".", "");
                        value = value.replace(".", "");
                        $(this).parent().find('div.rcost').html('<div class="blue">'+coverMonneyToString(value)+'</div>');
                    });
                    
                    <?php if($this->owner_list_array){ ?>
                    var availableOwner = [<?php echo $this->owner_list_array;?>];
                    $( 'input[name^="owner"]' ).autocomplete({
                        source: availableOwner
                    });
                    <?php } ?>
		        });
			});

			function del(obj){
				$(obj).parent().parent().remove();
			}
		</script>
    
    	<?php
            if(count($this->data['item'])){
			foreach($this->data['item'] as $item){
		?>
				<script language="javascript">
					$("form > dl.zend_form > dd#iplan2-element").append('<div class="fwrap"><div class = "mTit">Thông tin thành phần thiết bị</div><div class="content"><input type="hidden" value = "<?php echo $item['itemId']; ?>" name = "itemId[]" />'
															+'<div class = "row-1"><label class="first-row-label">Tên</label> <input type="text" name="item[]" value="<?php echo $item['itemName'] ?>" size="20" />'
															+'</div><div class = "row-2"><div class="row-first"><label class="first-row-label">Giá Mua</label>  <input type="text" name="priceItem[]" value = "<?php echo number_format($item['priceItem'], 0, ',', '.') ?>" size="20" /><div class="rcost"></div></div>'
															+'<div class="row-second"><label>Ngày mua</label> <input readOnly ="true" type="text" name="startDate[]" placeholder="mm/dd/yyyy" size="20" class="startDate" value = "<?php echo $this->time()->dataTimeToDateTime_3($item['startDate']) ?>" /></div>'
															+'<div class="clr"></div></div><div class = "row-5"><div class="row-first"><label class="first-row-label">Tài Sản</label> <input type="text" name="owner[]" size="20" value = "<?php echo $item['owner'] ?>" /></div>'
															+'<div class="clr"></div></div><div class = "row-4"><label class="first-row-label">Lịch sử</label> <textarea name="history[]" rows="3" cols ="50"><?php echo str_replace("\r\n",' ',$item['history']); ?></textarea></br>'															
															+'<label class="first-row-label">Thông Tin</label> <textarea name="info[]" rows="3" cols ="50"><?php echo str_replace("\r\n",' ',$item['info']); ?></textarea></br>'
															+'</div><input class="del" type="button" onclick="del(this);" value ="Xóa" /></div></div>');
				
                    $(function () {
    		            $(".startDate").datepicker({ changeMonth : true, changeYear: true, yearRange: '1950:3000' });
    					$('input[name^="priceItem"]').keydown(function(event) {
                        	if( !(event.keyCode == 8                                // backspace
                                || event.keyCode == 9                               // tab
                                || event.keyCode == 46                              // delete
                                || (event.keyCode >= 35 && event.keyCode <= 40)     // arrow keys/home/end
                                || (event.keyCode >= 48 && event.keyCode <= 57)     // numbers on keyboard
                                || (event.keyCode >= 96 && event.keyCode <= 105))   // number on keypad
                                ) {
                                    event.preventDefault();     // Prevent character input
                            }
                        });
                        $('input[name^="priceItem"]').keyup(function(){
                            $(this).val(partMonney($(this).val().replace(".", "")));
                            value = $(this).val().replace(".", "");
                            value = value.replace(".", "");
                            value = value.replace(".", "");
                            value = value.replace(".", "");
                            value = value.replace(".", "");
                            value = value.replace(".", "");
                            value = value.replace(".", "");
                            value = value.replace(".", "");
                            value = value.replace(".", "");
                            $(this).parent().find('div.rcost').html('<div class="blue">'+coverMonneyToString(value)+'</div>');
                        });
                        
                        <?php if($this->owner_list_array){ ?>
                        var availableOwner = [<?php echo $this->owner_list_array;?>];
                        $( 'input[name^="owner"]' ).autocomplete({
                            source: availableOwner
                        });
                        <?php } ?>
    		        });
				</script>
		<?php
			}			
        }
		if(isset($this->item)){
				foreach($this->item as $item){ ?>
				<script language="javascript">
					$("form > dl.zend_form > dd#iplan2-element").append('<div class="fwrap"><div class = "mTit">Thông tin thành phần thiết bị</div><div class="content">'
															+'<div class = "row-1"><label class="first-row-label">Tên</label> <input type="text" name="item[]" value="<?php echo $item->itemName ?>" size="20" />'
															+'</div><div class = "row-2"><div class="row-first"><label class="first-row-label">Giá Mua</label>  <input type="text" name="priceItem[]" value = "<?php echo number_format($item->priceItem, 0, ',', '.') ?>" size="20" /><div class="rcost"></div></div>'
															+'<div class="row-second"><label>Ngày mua</label> <input readOnly ="true" type="text" name="startDate[]" placeholder="mm/dd/yyyy" size="20" class="startDate" value = "<?php echo $this->time()->dataTimeToDateTime_3($item->startDate) ?>" /></div>'
															+'<div class="clr"></div></div><div class = "row-5"><div class="row-first"><label class="first-row-label">Tài Sản</label> <input type="text" name="owner[]" size="20" value = "<?php echo $item->owner ?>" /></div>'
															+'<div class="clr"></div></div><div class = "row-4"><label class="first-row-label">Lịch sử</label> <textarea name="history[]" rows="3" cols ="50"><?php echo str_replace("\r\n",' ',$item->history); ?></textarea></br>'															
															+'<label class="first-row-label">Thông Tin</label> <textarea name="info[]" rows="3" cols ="50"><?php echo str_replace("\r\n",' ',$item->info); ?></textarea></br>'
															+'</div><input class="del" type="button" onclick="del(this);" value ="Xóa" /></div></div>');
				
                    $(function () {
    		            $(".startDate").datepicker({ changeMonth : true, changeYear: true, yearRange: '1950:3000' });
    					$('input[name^="priceItem"]').keydown(function(event) {
                        	if( !(event.keyCode == 8                                // backspace
                                || event.keyCode == 9                               // tab
                                || event.keyCode == 46                              // delete
                                || (event.keyCode >= 35 && event.keyCode <= 40)     // arrow keys/home/end
                                || (event.keyCode >= 48 && event.keyCode <= 57)     // numbers on keyboard
                                || (event.keyCode >= 96 && event.keyCode <= 105))   // number on keypad
                                ) {
                                    event.preventDefault();     // Prevent character input
                            }
                        });
                        $('input[name^="priceItem"]').keyup(function(){
                            $(this).val(partMonney($(this).val().replace(".", "")));
                            value = $(this).val().replace(".", "");
                            value = value.replace(".", "");
                            value = value.replace(".", "");
                            value = value.replace(".", "");
                            value = value.replace(".", "");
                            value = value.replace(".", "");
                            value = value.replace(".", "");
                            value = value.replace(".", "");
                            value = value.replace(".", "");
                            $(this).parent().find('div.rcost').html('<div class="blue">'+coverMonneyToString(value)+'</div>');
                        });
                        
                        <?php if($this->owner_list){ ?>
                        var availableOwner = [<?php echo $this->owner_list;?>];
                        $( 'input[name^="owner"]' ).autocomplete({
                            source: availableOwner
                        });
                        <?php } ?>
    		        });
				</script>
			<?php if(!isset($item->itemId)){ ?>
					<script language="javascript">
						$("form > dl.zend_form > dd#iplan2-element").append('<div class="fwrap"><div class = "mTit">Thông tin thành phần thiết bị</div><div class="content">'
															+'<div class = "row-1"><label class="first-row-label">Tên</label> <input type="text" name="item[]" value="<?php echo $item->itemName ?>" size="20" />'
															+'</div><div class = "row-2"><div class="row-first"><label class="first-row-label">Giá Mua</label>  <input type="text" name="priceItem[]" value = "<?php echo number_format($item->priceItem, 0, ',', '.') ?>" size="20" /><div class="rcost"></div></div>'
															+'<div class="row-second"><label>Ngày mua</label> <input readOnly ="true" type="text" name="startDate[]" placeholder="mm/dd/yyyy" size="20" class="startDate" value = "<?php echo $this->time()->dataTimeToDateTime_3($item->startDate) ?>" /></div>'
															+'<div class="clr"></div></div><div class = "row-5"><div class="row-first"><label class="first-row-label">Tài Sản</label> <input type="text" name="owner[]" size="20" value = "<?php echo $item->owner ?>" /></div>'
															+'<div class="clr"></div></div><div class = "row-4"><label class="first-row-label">Lịch sử</label> <textarea name="history[]" rows="3" cols ="50"><?php echo str_replace("\r\n",' ',$item->history); ?></textarea></br>'															
															+'<label class="first-row-label">Thông Tin</label> <textarea name="info[]" rows="3" cols ="50"><?php echo str_replace("\r\n",' ',$item->info); ?></textarea></br>'
															+'</div><input class="del" type="button" onclick="del(this);" value ="Xóa" /></div></div>');
				
					</script>

			<?php }
				}
			}
			//edit item :: 07/11/2012 ::

        ?>
    </div>
</div>
